package com.android.li.temperature.util;

import java.io.File;
import java.io.RandomAccessFile;

import android.os.Build;
import android.os.Environment;

public class LogUtil {
    public final static String FILE_PATH = Environment.getExternalStorageDirectory() + "/PhoneData/";

    public final static String FILE_NAME_LOG = Build.BRAND + "_Thermal_value.log";

    public final static String FILE_NAME_TYPE = Build.BRAND + "_Thermal_name.log";

    public static void writeLogFile(String fileName, String content) {
        String strContent = content + "\n";
        try {
            File fileDir = new File(FILE_PATH);
            if (!fileDir.exists()) {
                fileDir.mkdirs();
                if (!fileDir.exists()) {
                    return;
                }
            }
            File file = new File(FILE_PATH, fileName);
            RandomAccessFile raf = new RandomAccessFile(file, "rw");
            raf.seek(file.length());
            raf.write(strContent.getBytes());
            raf.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void delLogFile() {
        File file = new File(FILE_PATH + FILE_NAME_LOG);
        if (file.exists()) {
            file.delete();
        }
    }

    public static void writeLogTypeFile(String content) {
        File file = new File(FILE_PATH + FILE_NAME_TYPE);
        if (file.exists()) {
            return;
        }

        writeLogFile(FILE_NAME_TYPE, content);
    }

    public static void writeLogFile(String content) {
        writeLogFile(FILE_NAME_LOG, content);
    }
}
